<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>员工档案添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../layuimini/css/public.css" media="all">
</head>
<body>
<form method="post" class="layui-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">用户姓名</label>
            <div class="layui-input-inline">
                <select name="empid" class="layui-input"  >
                    <option value="-1">全部员工</option>
                    <option th:each="d:${pname}" th:value="${d.id}" th:text="${d.empName}"></option>
                </select>
            </div>
        </div>
        <br/>
        <div class="layui-inline">
            <label class="layui-form-label">计划主题</label>
            <div class="layui-input-inline">
                <input type="text" name="theme" placeholder="请输入主题名称" class="layui-input">
            </div>
            <label id="theme" style="color: red;display: none">请输入主题名称</label>
        </div>
        <br/>
        <div class="layui-inline">
            <label class="layui-form-label">计划内容</label>
            <div class="layui-input-inline">
                <input type="text" name="content" placeholder="请输入计划内容" class="layui-input">
            </div>
            <label id="content" style="color: red;display: none">请输入计划内容</label>
        </div>
        <br/>
        <div class="layui-inline">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-inline">
                <input type="date" lay-verify="required" class="layui-input" name="start" id="kaishi">
            </div>
        </div>
        <br/>
        <div class="layui-inline">
            <label class="layui-form-label">结束时间</label>
            <div class="layui-input-inline">
                <input type="date" lay-verify="required" class="layui-input"name="end" id="jiesu">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">添加</button>
        </div>
    </div>
</form>
<script src="../layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    var $ = layui.jquery;
    $(function () {
        //获取当前时间
        var dateone =new Date();
        //获取当前年份
        var year =dateone.getFullYear();
        //获取当前月份
        var month = dateone.getMonth()+1<10 ? "0"+(dateone.getMonth()+1):(dateone.getMonth()+1);
        //获取下个月份
        var xmonth=dateone.getMonth()+2<10 ? "0"+(dateone.getMonth()+2):(dateone.getMonth()+2);
        //获取当前日期
        var date =dateone.getDate()<10 ? "0"+dateone.getDate():dateone.getDate();

        $("#kaishi").attr("max",year+"-"+xmonth+"-01");
        $("#kaishi").attr("min",year+"-"+month+"-"+date);
        $("#jiesu").attr("max",year+"-"+xmonth+"-01");
        $("#jiesu").attr("min",year+"-"+month+"-"+date);
    })
    layui.use(['form'], function () {
        var form = layui.form;
        var layer = layui.layer;

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            let theme=$(":input[name='theme']").val();
            if (theme==""){
                $("#theme").show();
                return false;
            }
            $(":input[name='theme']").click(function (){
                $("#theme").hide();
                return false;
            })
            let content=$(":input[name='content']").val();
            if (content==""){
                $("#content").show();
                return false;
            }
            $(":input[name='content']").click(function (){
                $("#content").hide();
                return false;
            })

            $.post('/plan/insertplan',data.field,function(res){
                if(res.data==="success"){
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                    parent.layui.table.reload('table-user');
                    parent.layer.msg(res.msg);
                }
            })
            return false;
        });
    });
</script>
</body>
</html>